import struct
import ctypes

import sys, getopt, os
def main(argv):
	opts, args = getopt.getopt(argv, "i:", ["ifile="])

	ifname = opts[0][1]
	ifile = open(ifname, 'r')
	st = os.stat(ifname)
	size  = st.ST_SIZE / 8

	buffer = ctypes.create_string_buffer(size * 8);
	i = 0
	for line in ifile :
		line = line.strip().split('\t')
		struct.pack_into('if', buffer, i*8, int(line[0]), float(line[1]))
		i+=1
	ifile.close()
	ofname = ifname.replace('.in', '.bin')
	ofile = open(ofname, 'wb')
	ofile.write(buffer)
	ofile.close()
	print "Bin file: ", ofname, " written"

if __name__ == "__main__" :
	main(sys.argv[1:])